package com;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;


public class talkWindow extends JFrame{
	JLabel jLabel;
	JTextField jTextField;
	JButton jButton;
	JTextArea jTextArea;
	JTextArea jTextArea2;
	public talkWindow() 
	   { 
	      super(); 
	      this.setSize(300, 400);
	      this.setBounds(400, 200, 400, 430);
	      this.getContentPane().setLayout(null);
	      this.add(getJTextArea());
	      this.add(getWriteArea());
	      this.add(getJButton());
	      this.setTitle("HelloWorld");
	      
	   } 
	  
	   private JTextArea getJTextArea() { 
	      if(jTextArea == null) { 
	    	  jTextArea = new JTextArea(100,100);
	    	  jTextArea.setBorder (BorderFactory.createLineBorder(Color.LIGHT_GRAY,2));
	    	  jTextArea.setBounds(25, 25, 340, 160);
	    	  jTextArea.setText("");
	    	  jTextArea.setWrapStyleWord(true);
	    	  jTextArea.setLineWrap(true);
	      } 
	      return jTextArea;
	   } 
	   
	   private JTextArea getWriteArea() { 
		      if(jTextArea2 == null) {
		    	  
		    	  jTextArea2 = new JTextArea(100,100);
		    	  jTextArea2.setBorder (BorderFactory.createLineBorder(Color.LIGHT_GRAY,2));
		    	  jTextArea2.setBounds(25, 210, 340, 100);
		    	  jTextArea2.setText("");
		    	  jTextArea2.setWrapStyleWord(true);
		    	  jTextArea2.setLineWrap(true);
		      } 
		      return jTextArea2;
		   } 
	  
	  
	   private JButton getJButton() { 
	      if(jButton == null) {
	         jButton = new javax.swing.JButton(); 
	         jButton.setBounds(245, 330, 120, 27); 
	         jButton.setText("Send Message");
	         jButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					String data = jTextArea.getText();
					
					String talkDetail = jTextArea2.getText();
					if(data!=null&&data.trim().equals("")){
						jTextArea.append(App.userName+":"+talkDetail);
					}else{
						jTextArea.append("\r\n"+App.userName+":"+talkDetail);
					}
					
					setBackground(Color.PINK);
					jTextArea2.setText("");
				}
			});
	         //jButton.setIcon(new ImageIcon("E:/MF_wordspace/MF_SVN/Source/ccc/src/img/2008521204245421_2.jpg"));
	      }
	      return jButton;
	   }
	   public void paint(Graphics g) {
		   super.paint(g);
		   jTextArea2.requestFocus();
		  }

}
